package engine.display.Story.ActionItem
{
	import engine.data.ResPath;
	import engine.display.Story.StoryVo;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import newx.com.loader.SwfLoader;

	public class PlayStorySWF extends BaseAction
	{
		private static var _self:PlayStorySWF;
		private var _showSpace:Sprite;
		
		public function PlayStorySWF()
		{
			super();
			_showSpace	=	new Sprite();
			this.addChild(_showSpace);
		}
		public static function getInstance():PlayStorySWF
		{
			if(_self == null)
			{
				_self	=	new PlayStorySWF();
			}
			return _self;
		}
		override public function showInfo(val:StoryVo):void
		{
			clear();
			SwfLoader.StartLoad(ResPath.STORY + val.swfURL,null,completeHandle);
		}
		/**
		 * 动画加载完成
		 * @param val
		 * 
		 */		
		private function completeHandle(val:MovieClip,pList:Array):void
		{
			if(val == null)
			{
				actionOver();
				return;
			}
			_showSpace.addChild(val);
			val.addFrameScript(val.totalFrames -1, 
				function ():void
				{
					val.stop()
					actionOver();
				}
			)
			val.gotoAndPlay(2);
		}
		/**
		 * 清空当前显示内容
		 */		
		private function clear():void
		{
			while(_showSpace.numChildren > 0)
			{
				_showSpace.removeChildAt(0);
			}
		}
	}
}